import Marquee from "./components/Marquee";
import ConfirmPopup from "./components/popups/ConfirmPopup"
import ResManager from "./core/ResManager";
import { HttpRequest } from "./net/HttpRequest";
import { Utils } from "./utils/Utils";
// import io from 'socket.io-client';

const { ccclass, property } = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    @property(Marquee)
    marquee: Marquee = null

    @property(cc.Prefab)
    popBox: cc.Prefab = null

    popCtrl = null

    onLoad() {
        console.log('test111111111')
        let teststr = '攻击增加{0}，血量增加{1}';
        console.log(teststr.format([100, 2000]));

        // let obj = {
        //     resourceId: "config_language_zh",
        //     resourcePath: 'config/language_zh',
        //     resourceType: 'csv',
        //     key: ["languageId"],
        // }
        // ResManager.ins().load(obj,(res)=>{
        //     console.log('资源加载成功',res);
        // });

        this.AsyncGetConfig();
    }

    async AsyncGetConfig() {
        let obj = {
            resourceId: "config_language_zh",
            resourcePath: 'config/language_zh',
            resourceType: 'csv',
            key: ["languageId"],
        }
        let _config = await ResManager.ins().getResAsync(obj);
        console.log(_config);
        console.log(_config['sign01'].text.format([10]));
    }

    start() {
        this.marquee.push(['大家好，我是小明', '欢迎欢迎欢迎欢迎欢迎！']);
        this.marquee.play();

        // var socket = io('http://127.0.0.1:3000');
        // socket.on('connected', () => {
        //     console.log('Socket connected');
        // });

        let httpPromise = HttpRequest.ins().httpPromise(':3000', { username: 'aaa', password: 'password' }, 'get', () => {
            console.log('错误处理1')
        })
        httpPromise.then((data) => {
            console.log('1111111111',data);
            var socket = io();
            socket.on('connected', () => {
                console.log('Socket connected');
            });
        }).catch(() => {
            console.log('错误处理2')
        })
    }

    btnClick() {
        if (this.popCtrl) {
            this.popCtrl.show()
        } else {
            let node = cc.instantiate(this.popBox)
            node.parent = this.node
            this.popCtrl = node.getComponent(ConfirmPopup)
            this.popCtrl.show({
                title: '提示',
                content: '弹窗测试',
                confirmCallback: () => {
                    console.log('xxxx')
                },
            })
        }
    }

}
